#include<iostream>
#include<cstring>
using namespace std;
const int N = 1e4 + 10;
int f[N], w[N], v[N], p[N];
int n, m, k;
int find(int x)
{
	if (x != p[x]) {
		p[x] = find(p[x]);
	}
	return p[x];
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> k >> m;
		memset(v, 0, sizeof(v));
		memset(f, 0, sizeof(f));
		memset(p, 0, sizeof(p));
		memset(w, 0, sizeof(w));
		for (int i = 2; i <= n; i++) {
			cin >> v[i] >> w[i];
		}
		for (int i = 1; i <= n; i++) {
			p[i] = i;
		}
		while (k--) {
			int a, b;
			cin >> a >> b;
			a = find(a);
			b = find(b);
			if (a != b) {
				p[a] = b;
			}
		}
		for (int i = 1; i <= n; i++) {
			int a = find(1);
			int b = find(i);
			if (a == b) {
				for (int j = m; j >= v[i]; j--) {
					f[j] = max(f[j], f[j - v[i]] + w[i]);
				}
			}
		}
		cout << f[m] << endl;
	}
	return 0;
}